package com.gopay.scheduler.job;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.common.constants.cust.OprStatConstants;
import com.gopay.common.domain.user.CauthOperatorInfo;
import com.gopay.common.user.dao.OprInfoQueryDAO;
import com.gopay.common.user.manager.OprInfoQueryManager;
import com.gopay.common.util.DateUtils;
import com.gopay.scheduler.GopayBaseJob;
/**
 * 操作员信息维护，主要是对到期操作员进行锁定
 * @OperatorInfoManagerJob.java
 * @author 曹永峰
 *
 */
public class OperatorInfoManagerJob extends GopayBaseJob{
	
	private OprInfoQueryDAO oprInfoQueryDao;
	private OprInfoQueryManager oprInfoQueryManager;
	
	private Logger logger = LoggerFactory
			.getLogger(OperatorInfoManagerJob.class);
	/**
	 * 定时任务，锁定到期操作员
	 */
	public void doJobInternal(){
		String today = DateUtils.now2string("yyyyMMdd");
		logger.info("Query due to the operator...");
		//获取到期用户列表
		List<CauthOperatorInfo> dueOpr = oprInfoQueryDao.getDueOpr(today);
		
		//没有到期用户，任务结束
		if(dueOpr==null||dueOpr.size()==0){
			logger.info("it has no due to operator...");
			return;
		}
		
		logger.info(dueOpr.size() + " operator has expired, locking in due...");
		
		for (CauthOperatorInfo operInfo : dueOpr) {
			operInfo.setOperStatus(OprStatConstants.OPR_STATE_DUE_LOCK);
			operInfo.setLastUpdTs(new Date());
		}
		try{
			oprInfoQueryManager.updateOpr(dueOpr);
		}catch (Exception e) {
			logger.info("due to operator lock failed...");
			e.printStackTrace();
		}
		
	}
	
	
	@Resource(name="oprInfoQueryDao")
	public void setOprInfoQueryDao(OprInfoQueryDAO oprInfoQueryDao) {
		this.oprInfoQueryDao = oprInfoQueryDao;
	}

	@Resource(name="oprInfoQueryManager")
	public void setOprInfoQueryManager(OprInfoQueryManager oprInfoQueryManager) {
		this.oprInfoQueryManager = oprInfoQueryManager;
	}

}
